package cn.maven.main;

import cn.maven.module.Table;
import cn.maven.utils.TableUtil;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EntityHandler {

    private Generator generator = new Generator();

    public void exectue() throws IOException, TemplateException {
        //获取table对应的实例
        List<Table> tableList = TableUtil.getTable();
        Map<String, Object> param = new HashMap<>();
        //设置模板路径
        String templatePath = this.getClass().getClassLoader().getResource("").getPath();
        System.out.println(templatePath);
        String savePath = "F:\\IdeaWorkSpace\\national-reading\\src\\main\\java\\com\\data\\entity";

        for (Table table : tableList) {
            param.put("table", table);
            generator.init(templatePath);

            generator.process("entity.ftl", savePath + "/" + table.getClassName() + ".java", param);
        }
    }

   /* public static void main(String[] args) throws IOException, TemplateException {
        EntityHandler moduleHandler = new EntityHandler();
        moduleHandler.exectue();
    }*/
}
